package ynu.edu.user.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.common.result.Result;
import ynu.edu.user.service.UserService;
import ynu.edu.user.vo.UserVO;

/**
 * 内部用户控制器，提供给其他微服务调用的API
 * 这些API不需要JWT认证
 */
@RestController
@RequestMapping("/internal")
@RequiredArgsConstructor
public class InternalUserController {

    private final UserService userService;

    /**
     * 根据用户ID获取用户信息（内部API）
     */
    @GetMapping("/users/{id}")
    public Result<UserVO> getUserById(@PathVariable Long id) {
        UserVO userVO = userService.getUserInfo(id);
        return Result.success(userVO);
    }

    /**
     * 根据用户ID获取用户名（内部API）
     */
    @GetMapping("/users/{id}/name")
    public Result<String> getUserNameById(@PathVariable Long id) {
        UserVO userVO = userService.getUserInfo(id);
        return userVO != null ? 
               Result.success(userVO.getUsername()) : 
               Result.failed("用户不存在");
    }
} 